<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <table border="1" cellspacing="0">
        <thead>
            <tr>
                <th>学号</th>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>班级</th>
            </tr>
        </thead>
        <tbody>
            <!-- <tr>
                <td>1</td>
                <td>张三</td>
                <td>男</td>
                <td>18</td>
                <td>2302</td>
            </tr>
            <tr>
                <td>1</td>
                <td>张三</td>
                <td>男</td>
                <td>18</td>
                <td>2302</td>
            </tr>
            <tr>
                <td>1</td>
                <td>张三</td>
                <td>男</td>
                <td>18</td>
                <td>2302</td>
            </tr>
            <tr>
                <td>1</td>
                <td>张三</td>
                <td>男</td>
                <td>18</td>
                <td>2302</td>
            </tr> -->
        </tbody>
    </table>
    <script>
        var users = [
            {id:1,name:'张三',gender:'男',age:18,classroom:'2302'},
            {id:2,name:'李四',gender:'男',age:28,classroom:'2303'},
            {id:3,name:'王五',gender:'男',age:38,classroom:'2304'},
            {id:4,name:'小芳',gender:'女',age:19,classroom:'2301'}
        ]
        // var data = ''
        // users.forEach(function(item){
        //     data +=`
        //     <tr>
        //         <td>${item.id}</td>
        //         <td>${item.name}</td>
        //         <td>${item.gender}</td>
        //         <td>${item.age}</td>
        //         <td>${item.classroom}</td>
        //     </tr>
            
        //     `
        // }); 

        var res = users.reduce(function(prev,item){
            return prev += `
            <tr>
                <td>${item.id}</td>
                <td>${item.name}</td>
                <td>${item.gender}</td>
                <td>${item.age}</td>
                <td>${item.classroom}</td>
            </tr>
            
            `
        },'')

        // data = '' + '<tr></tr>'+'<tr></tr>' + '<tr></tr>' + '<tr></tr>' 

        // '<tr></tr><tr></tr><tr></tr><tr></tr>'

        // document.querySelector('tbody').innerHTML = data
        document.querySelector('tbody').innerHTML = res


    </script>
</body>
</html>